<?php
/**
 * Created by PhpStorm.
 * User: lichuang
 * Date: 2022/9/21
 * Function: 示例
 */

namespace app\controllers;

use Yii;
use app\server\Api;
use app\logic\DemoLogic;
use yii\base\ErrorException;

class DemoController extends BaseController
{
    private $demoLogic = null;

    public function init()
    {
        parent::init();

        if ($this->demoLogic == null) {

            // TOKEN信息
            $tokenData = $this->tokenData;
            // 逻辑
            $this->demoLogic = new DemoLogic($tokenData);
        }
    }

    // 用户登录
    public function actionLogin()
    {
        $request = Yii::$app->request;
        if ($request->isPost) {
            $post = $request->post();
            try {
                $res = $this->demoLogic->login($post);
                Api::json($res);
            } catch (ErrorException $e) {
                Api::error($e->getCode(), $e->getMessage());
            }
        }
    }
}